# coding:utf-8
import time

from lib.base import Base
from page.android import train_high_speed_rail_travel_page, train_abroad_page, train_select_city_page, train_order_page, \
    train_rush_ticket_order_list_page, train_choose_data_page, train_travel_service_page, train_index_page, \
    train_user_center_page

__author__ = 'weixin.yuan'


class TrainIndex(Base):
    """火车票首页"""
    def __init__(self, method_name):
        Base.__init__(self, method_name)

        """
        本页元素
        """
        self.qiangpiao_btn = train_index_page.elements['抢票按钮']
        self.high_speed_rail_travel_btn = train_index_page.elements['高铁游按钮']
        self.train_abroad_btn = train_index_page.elements['火车境外按钮']
        self.koulingma_btn = train_index_page.elements['口令码兑换按钮']
        self.close_koulingma_btn = train_index_page.elements['关闭口令按钮']
        self.shurukouling_title = train_index_page.elements['输入口令title']
        self.dep_city_btn = train_index_page.elements['始发地按钮']
        self.arr_city_btn = train_index_page.elements['目的地按钮']
        self.dep_arr_swap_btn = train_index_page.elements['始发地目的地调换按钮']
        self.choose_data_btn = train_index_page.elements['选择时间按钮']
        self.only_steel_radio = train_index_page.elements['只看高铁动车']
        self.student_ticket_radio = train_index_page.elements['学生票']
        self.search_btn = train_index_page.elements['搜索按钮']
        self.topic_btn = train_index_page.elements['话题按钮']
        self.my_order_btn = train_index_page.elements['我的订单']
        self.travel_service_btn = train_index_page.elements['旅行服务']
        self.user_center_btn = train_index_page.elements['个人中心']

        """
        外部页面元素
        """
        self.train_title = train_order_page.elements['火车票title']
        self.travel_service_title = train_travel_service_page.elements['旅行服务title']
        self.speed_pkg_btn = train_user_center_page.elements['加速包按钮']
        self.select_city_title = train_select_city_page.elements['选择城市title']
        self.choose_data_title = train_choose_data_page.elements['出发日期title']
        self.add_rush_ticket_btn = train_rush_ticket_order_list_page.elements["添加抢票按钮"]
        self.from_place_title = train_high_speed_rail_travel_page.elements["出发地title"]
        self.london_btn = train_abroad_page.elements["伦敦选项"]

    def test_train_index(self):
        """火车票首页check"""
        self.open_schema_android('6002')

        self.click(self.koulingma_btn)  # 点击口令码
        self.check(self.shurukouling_title)
        self.click(self.close_koulingma_btn)

        self.click(self.dep_city_btn)  # 点击始发地
        self.check(self.select_city_title)
        self.back()

        self.click(self.arr_city_btn)  # 点击目的地
        self.check(self.select_city_title)
        self.back()

        # 获取始发地与目的地城市值
        dep_city_text_b = self.text(self.dep_city_btn)
        arr_city_text_b = self.text(self.arr_city_btn)
        self.click(self.dep_arr_swap_btn)  # 点击始发地和目的地交换按钮
        dep_city_text_a = self.text(self.dep_city_btn)
        arr_city_text_a = self.text(self.arr_city_btn)

        assert dep_city_text_a == arr_city_text_b, '始发地与目的交换失败'
        assert dep_city_text_b == arr_city_text_a, '始发地与目的交换失败'

        self.click(self.choose_data_btn)  # 点击选择日期
        self.back()

        self.click(self.only_steel_radio)  # 点击只看高铁
        self.click(self.only_steel_radio)
        self.click(self.student_ticket_radio)  # 点击学生票
        self.click(self.student_ticket_radio)

        self.click(self.my_order_btn)  # 点击我的订单
        # self.check(self.train_title)
        time.sleep(5)
        self.back()

        self.click(self.travel_service_btn)  # 点击旅行服务
        self.check(self.travel_service_title)
        self.back()

        self.click(self.user_center_btn)  # 点击个人中心
        self.check(self.speed_pkg_btn)
        self.back()

        self.click(self.qiangpiao_btn)  # 点击抢票
        self.check(self.add_rush_ticket_btn)
        self.back()

        self.click(self.high_speed_rail_travel_btn)  # 点击高铁游，点击高铁游存在红屏幕现象，只有在beat包有这个问题
        self.check(self.from_place_title)
        self.back()

        self.click(self.train_abroad_btn)  # 点击火车境外
        self.check(self.london_btn)
        self.back()
